package com.gitee.wsl.time.calendar.bean

import androidx.compose.runtime.Immutable
import com.gitee.wsl.time.YearMonth
import com.gitee.wsl.time.calendar.style.DayPosition
import com.gitee.wsl.time.minusMonths
import com.gitee.wsl.time.plusMonths
import com.gitee.wsl.time.yearMonth
import kotlinx.datetime.LocalDate
import kotlin.time.ExperimentalTime

/**
 * Represents a day on the calendar.
 *
 * @param date the date for this day.
 * @param position the [com.gitee.wsl.time.calendar.style.DayPosition] for this day.
 */
@Immutable
data class CalendarDay(val date: LocalDate, val position: DayPosition)


// Find the actual month on the calendar where this date is shown.
@OptIn(ExperimentalTime::class)
val CalendarDay.positionYearMonth: YearMonth
    get() = when (position) {
        DayPosition.InDate -> date.yearMonth.plusMonths(1)
        DayPosition.RangeDate -> date.yearMonth
        DayPosition.OutDate -> date.yearMonth.minusMonths(1)
    }